#include "head.h"
#include "time.h"
void grades()
{
        system("clear");
        srand(time(NULL));
        int grade = 0;
        int i = 0;
        int Grades[10]; // 存成绩
        while (i < 10)
        {
                grade = rand() % 100 + 1;
                if (grade > 100 || grade < -1)
                {
                        printf("乱搞\n");
                        break;
                }
                // if (-1 == grade)
                //         break;
                Grades[i] = grade;
                i++;
                switch (grade / 10)
                {
                case 10:
                case 9:
                        printf("成绩为%d", grade);
                        printf("等级为A\n");
                        break;
                case 8:
                        printf("成绩为%d", grade);
                        printf("等级为B\n");
                        break;
                case 7:
                        printf("成绩为%d", grade);
                        printf("等级为C\n");
                        break;
                case 6:
                        printf("成绩为%d", grade);
                        printf("等级为D\n");
                        break;
                case 5:
                case 4:
                case 3:
                case 2:
                case 1:
                case 0:
                        printf("成绩为%d", grade);
                        printf("不及格\n");
                        break;
                default:
                        printf("错误！！！\n");
                        break;
                }
        }
        // 排成绩
        int change = 0;
        for (int z = 0; z < 10 - 1; z++) // 排列z次
        {
                for (int y = 0; y < 10 - (z + 1); y++) // 每次排列，对相邻数比较，并将最大数往后放
                {
                        if (Grades[y] > Grades[y + 1]) // 比较相邻元素
                        {
                                change = Grades[y];
                                Grades[y] = Grades[y + 1];
                                Grades[y + 1] = change;
                        }
                }
        }
        printf("冒泡排序：\n");
        for (int j = 0; j < 10; j++) // 输出排序后的数组
        {
                printf("Grades[%d] = %d\t", j, Grades[j]);
                if ((j + 1) % 5 == 0)
                {
                        putchar('\n');
                }
        }
}